<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            display: flex;
            justify-content: center;
        }
        div{
           
        }
    </style>
</head>
<body>
    <div>
        <input type="text" name="" id="sum1"> + 
        <input type="text" name="" id="sum2"> = <span id="span">?</span> 
        <button id="btn">求和</button>
    </div>
    <script>
        var sum1 = document.getElementById('sum1')
        var sum2 = document.getElementById('sum2')
        var btn = document.getElementById('btn')
        var span = document.getElementById('span')

        sum1.onkeypress = function(e){
            e.keycode
            console.log( e.keycode);
        }

        btn.onclick = function(){
            //  console.log(  parseInt(sum1.value)+ parseInt(sum2.value));
             span.innerText = parseInt(sum1.value)+ parseInt(sum2.value)         
             
        }
    </script>
</body>
</html>